<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑投标信息</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">


        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目类别</label>
                        <div class="layui-input-block">
                            <input type="text" id="entype_name" value="" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>委托方</label>
                        <div class="layui-input-block">
                            <input type="text" name="weier" id="weier" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" readonly placeholder="系统自动生成编号" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">招标代理公司</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhaounit" id="zhaounit" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>投标文件递交方式</label>
                        <div class="layui-input-block">
                            <div id="touditype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开标时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="kaidt" id="kaidt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-hide entype2">
                <div class="layui-form-item ">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">资质类型</label>
                            <div class="layui-input-block">
                                <div id="bidtype"></div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>投标负责人</label>
                            <div class="layui-input-block">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=touer&type=user&single=1', '770px', '490px');"></div>
                                    <div class="tanxiannei" id="touer"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=touer&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                                <div id="touer_tanerror" class="tanerrormsg"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item ">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>投标保证金金额(元)</label>
                            <div class="layui-input-block">
                                <input type="text" id="toufee" name="toufee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">投标保证金说明</label>
                            <div class="layui-input-block">
                                <input type="text" name="toushuo" id="toushuo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item ">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12 layui-hide entype3">
                        <label class="layui-form-label">管理费费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" id="guanrate" name="guanrate" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-hide entype3">
                <div class="layui-form-item ">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">成本票提交比例(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="piaorate" name="piaorate" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">居间费比例(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="jianrate" name="jianrate" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item ">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label">招标方</label>
                            <div class="layui-input-block">
                                <input type="text" name="zhaoname" id="zhaoname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">所在地</label>
                            <div class="layui-input-block" style="z-index: 1;">
                                <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item height_auto ">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">项目说明</label>
                        <div class="layui-input-block">
                            <textarea id="bidshuo" name="bidshuo" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>

        </div>

        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>投标单位明细</span></div>
                        <div>
                            <button type="button" onclick="choose_tou()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择自有单位</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_copy_row">复制行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>投标单位</th>
                            <th><text>*</text>性质</th>
                            <th class="listentype1">报名费(元)</th>
                            <th class="listentype1">资质使用费(元)</th>
                            <th class="listentype1">资审费(元)</th>
                            <th class="listentype1">标书费用(元)</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

    </div>
</form>
<script>
    var param_entype;
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            weier: {required: true},
            toufee: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            weier: {required: "请输入"},
            toufee: {required: "请输入"},
        }
    });

    function choose_userid(obj, dom){
        var index = $(obj).parents('tr').find('td:first-child').text();
        index = parseInt(index) - 1;
        openPage('../public/choose_userpart.php?dom='+dom+'&index='+index+'&page=bidtou','770px','490px');
    }

    function set_list_user_tags(data) {
        var str = '';
        for (var key in data){
            data[key].part = data[key].part || '';
            str += '<div class="tags">';
            str += '<div ' +
                'title="'+data[key].name+'" '+
                'data-id="'+data[key].id+'" '+
                'data-part="'+data[key].part+'" '+
                '>';
            str += data[key].name+'</div>';
            str += '<i class="layui-icon" onclick="closeTanTag(this)">&#x1006;</i></div>';
        }
        return str;
    }

    function choose_tou(){
        openPage('../public/choose_tou.php?page=bid&choose_type=checkbox','80%','80%');
    }

    var pub_touxing;

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_bid_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                param_entype = data.entype;
                if(param_entype == 1){
                    $(".entype2").removeClass('layui-hide');
                    $(".entype3").removeClass('layui-hide');
                    $("#entype_name").val('中标项目');
                }else if(param_entype == 2){
                    $(".entype2").removeClass('layui-hide');
                    $("#entype_name").val('陪标项目');
                }else{
                    $("#entype_name").val('代写项目');
                }


                $("#name").val(data.name);
                $("#number").val(data.number);
                $("#weier").val(data.weier);
                $("#zhaoname").val(data.zhaoname);
                $("#addr").val(data.addr);
                $("#zhaounit").val(data.zhaounit);
                $("#gongfee").val(data.gongfee);
                $("#kaidt").val(data.kaidt);
                $("#toufee").val(data.toufee);
                $("#toushuo").val(data.toushuo);
                $("#bidshuo").val(data.bidshuo);
                $("#guanrate").val(data.guanrate);
                $("#jianrate").val(data.jianrate);
                $("#piaorate").val(data.piaorate);
                $("#explain").val(data.explain);

                if(data.touer_info.length > 0){
                    tan_tags_init('#touer', data.touer_info);
                }


                $("#areas").val(data.areas);
                load_areas('areas', res.data.areas, 3);
                xmselect_dan('bidtype', res.data.bidtype, data.bidtype);
                xmselect_dan('zhaotype', res.data.zhaotype, data.zhaotype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#zhaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#zhaotype").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('touditype', res.data.touditype, data.touditype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#touditype").find('xm-select').removeClass('error');
                    }else{
                        $("#touditype").find('xm-select').addClass('error');
                    }
                });



                pub_touxing = res.data.touxing;
                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><input type="text" class="layui-input touunit"></td>';
                listAddStr += '<td><div class="touxing"></div></td>';
                listAddStr += '<td class="listentype1"><input type="number" class="layui-input baofee"></td>';
                listAddStr += '<td class="listentype1"><input type="number" class="layui-input zhifee"></td>';
                listAddStr += '<td class="listentype1"><input type="number" class="layui-input shenfee"></td>';
                listAddStr += '<td class="listentype1"><input type="number" class="layui-input biaofee"></td>';

                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1, {name:'touxing', data:res.data.touxing, value:''});



                var list = res.data.list;
                if(list.length > 0){
                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><input type="text" class="layui-input touunit" id="'+list[key].id+'" value="'+list[key].touunit+'"></td>';
                        str += '<td><div class="touxing touxing'+nums+'" key="'+nums+'"></div></td>';
                        str += '<td class="listentype1"><input type="number" class="layui-input baofee" value="'+list[key].baofee+'"></td>';
                        str += '<td class="listentype1"><input type="number" class="layui-input zhifee" value="'+list[key].zhifee+'"></td>';
                        str += '<td class="listentype1"><input type="number" class="layui-input shenfee" value="'+list[key].shenfee+'"></td>';
                        str += '<td class="listentype1"><input type="number" class="layui-input biaofee" value="'+list[key].biaofee+'"></td>';

                        str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                        str += '</tr>';
                        $("#list_list").append(str);
                        xmselect_list_dan('touxing'+nums, res.data.touxing, list[key].touxing);
                    }
                }
                update_refresh_row_func()



                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            data.field.touer = tan_tags_getvalue("#touer", 'user');


            var validRes = $("#commentForm").valid();

            if(!data.field.zhaotype){
                $("#zhaotype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#zhaotype").find('xm-select').removeClass('error');
            }

            if(!data.field.touditype){
                $("#touditype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#touditype").find('xm-select').removeClass('error');
            }

            if(param_entype == 1 || param_entype == 2){
                if(!data.field.touer){
                    $("#touer").parents('.tanxian').addClass('tanerror');
                    $('#touer_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#touer").parents('.tanxian').removeClass('tanerror');
                    $('#touer_tanerror').text('');
                }

            }

            if(!validRes){return false;}


            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var id = $(this).find('.touunit').attr('id') || 0;
                    var touunit = $(this).find('.touunit').val();
                    var touxing = $(this).find('.touxing').find('input').val();
                    var baofee = $(this).find('.baofee').val();
                    var zhifee = $(this).find('.zhifee').val();
                    var shenfee = $(this).find('.shenfee').val();

                    var biaofee = $(this).find('.biaofee').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(!touunit){
                        throw new Error('第'+index+'行，请输入投标单位');
                    }
                    if(!touxing){
                        throw new Error('第'+index+'行，请选择性质');
                    }

                    list.push({
                        id:id,
                        touunit:touunit,
                        touxing:touxing,
                        baofee:baofee,
                        zhifee:zhifee,
                        shenfee:shenfee,
                        biaofee:biaofee,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;



            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_bid_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });




    function update_refresh_row_func() {
        render_date();
        render_from();
        if(param_entype == 1){
            $(".listentype1").removeClass('layui-hide');
        }else if(param_entype == 2){
            $(".listentype1").removeClass('layui-hide');
        }else{
            $(".listentype1").addClass('layui-hide');
        }


        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }



</script>
</body>
</html>
